<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">

    <xblock>
        <button class="layui-btn" onclick="save()">保存</button>
        <%--        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>--%>
        <span style="line-height:40px;margin-left: 200px;">
            <c:set value="${fn:split(versionName,'-')}" var="names"/>
            <c:forEach items="${names}" var="name" varStatus="status">
                <c:choose>
                    <c:when test="${status.index==0}">
                        包名:${name}
                    </c:when>
                    <c:when test="${status.index==1}">
                        平台:${name}
                    </c:when>
                    <c:when test="${status.index==2}">
                        版本号:${name}
                    </c:when>
                </c:choose>
            </c:forEach>
        </span>
        <span class="x-right" style="line-height:40px">共有数据：${data.data.switchData.size()} 条</span>
    </xblock>
    <table class="layui-table layui-form">
        <thead>
        <tr>
            <%--            <th width="20">--%>
            <%--                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i--%>
            <%--                        class="layui-icon">&#xe605;</i></div>--%>
            <%--            </th>--%>
            <th width="50">序号</th>
            <th>描述</th>
            <th width="200">key值</th>
            <th width="80">审核开关</th>
            <th width="200">状态</th>
        </thead>
        <tbody class="x-cate" id="switchData">
        <c:forEach items="${data.data.switchData}" var="switchData" varStatus="index">

            <tr cate-id='1' fid='0'>
                    <%--                <td>--%>
                    <%--                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary" versionData-id='2'><i--%>
                    <%--                            class="layui-icon">&#xe605;</i></div>--%>
                    <%--                </td>--%>
                <td>${index.count}</td>
                <td class="switchDesc">${switchData.switchDesc}</td>
                <td class="switchKeyName">${switchData.switchKeyName}</td>
                <td class="checkFlag">
                    <c:if test="${switchData.checkFlag==1}">
                        <input disabled="disabled" type="checkbox" name="switch" lay-text="是|否" checked="checked"
                               lay-skin="switch">

                    </c:if>
                    <c:if test="${switchData.checkFlag==0}">
                        <input disabled="disabled" type="checkbox" name="switch" lay-text="是|否" lay-skin="switch">
                    </c:if>
                </td>
                <td class="functionSwitch">
                    <c:if test="${switchData.functionSwitch==1}">
                        <input type="checkbox" name="switch" lay-text="开启|关闭" checked="checked" lay-skin="switch">

                    </c:if>
                    <c:if test="${switchData.functionSwitch==0}">
                        <input type="checkbox" name="switch" lay-text="开启|关闭" lay-skin="switch">
                    </c:if>
                </td>


            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
<style type="text/css">

</style>
<script>
    layui.use(['form'], function () {
        form = layui.form;

    });


    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            $(obj).parents("tr").remove();
            layer.msg('已删除!', {icon: 1, time: 1000});
        });
    }

    function save() {
        var switchDescList = new Array();
        var switchKeyNameList = new Array();
        var functionSwitchList = new Array();
        var checkFlagList = new Array();
        var dataArray = new Array();
        $(".switchDesc").each(function () {
            switchDescList.push($(this).text())
        })
        $(".switchKeyName").each(function () {
            switchKeyNameList.push($(this).text())
        })
        $(".functionSwitch").each(function () {
            var data = $(this).text().replaceAll("\n", "").replaceAll(" ", "");
            if (data == '开启')
                functionSwitchList.push('1')
            else
                functionSwitchList.push('0')
        })
        $(".checkFlag").each(function () {
            var data = $(this).text().replaceAll("\n", "").replaceAll(" ", "");
            if (data == '是')
                checkFlagList.push('1')
            else
                checkFlagList.push('0')
        })
        $.each(switchDescList, function (index, value) {
            var jsonObject = new Object();
            jsonObject.switchDesc = value;
            jsonObject.switchKeyName = switchKeyNameList[index];
            jsonObject.functionSwitch = functionSwitchList[index];
            jsonObject.checkFlag = checkFlagList[index];
            dataArray.push(jsonObject);

        });

        $.post("./saveSwitch", {versionName: '${versionName}', data: JSON.stringify(dataArray)}, function (result) {
            if (result.status)
                layer.msg(result.message, {icon: 1, time: 1000});
            else
                layer.msg(result.message, {icon: 2, time: 1000});
        });
    }

    function delAll(argument) {

        var versionData = tableCheck.getData();

        layer.confirm('确认要删除吗？' + versionData, function (index) {
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
    }
</script>
<script>var _hmt = _hmt || [];
(function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>